<!--
 * @Author: MrLee
 * @Date: 2024-08-24 10:19:44
 * @LastEditors: MrLee
 * @LastEditTime: 2024-08-24 20:38:48
 * @Description: 请填写简介
-->
<template>
  <custom-navbar title="内推" :autoBack="true" leftIconColor="#303133" />
  <Tabbar :tabList="tabList" @tabChange="tabChange" />
  <up-gap height="30rpx" />
  <view class="bg-#f6f7f8 px-22rpx" v-if="activeTab == 0">
    <view
      v-for="(item, index) in list"
      :key="index"
      class="job-item mb-32rpx bg-#fff flex items-center px-40rpx py-24rpx shadow-[0px_6px_16px_0px_rgba(191,191,191,0.26)] rounded-[20rpx]"
    >
      <view class="relative mr-[20rpx]">
        <image
          src="https://yiliao.test03.qcw800.com/static/images/tab/user-01.png"
          class="block h-[20rpx] w-[20rpx] absolute rigth-0 bottom-[5rpx]"
          style="right: 0"
        />
        <image class="w-72rpx h-72rpx rounded-[50%]" :src="item.teacher_avatar" />
      </view>
      <view class="flex flex-col justify-center">
        <view class="mb-14rpx flex items-center justify-between">
          <view class="text-left text-[32rpx] text-[#1d2129]">
            {{ item.teacher_name }}
          </view>
        </view>
        <view class="flex items-center text-left text-[26rpx] text-[#6e6d72]">
          <view
            v-for="(itemTab, indexTab) in item.tabs"
            :key="indexTab"
            class="flex items-center justify-center"
          >
            <view>{{ itemTab.label }}</view>
            <view
              v-if="indexTab != item.tabs.length - 1"
              class="mx-10rpx h-28rpx w-2rpx bg-#6e6d72"
            />
          </view>
        </view>
      </view>
    </view>
  </view>

  <JobList :job-list="jobList" :isreferral="true" v-else />
</template>
<script setup lang="ts">
import Tabbar from "@/pages/components/tabbar/index.vue";
import JobList from "@/pages/components/jobList/index.vue";
// import home06 from "@/static/images/tab/home-06.png";
// import home10 from "@/static/images/tab/home-10.png";

// import userCatch01 from "@/static/images/tab/user-header.png";
import { userTeacherRecommend, userJobList } from "@/api/user";

const home06 = "https://yiliao.test03.qcw800.com/static/images/tab/home-06.png";
const home10 = "https://yiliao.test03.qcw800.com/static/images/tab/home-10.png";
const userCatch01 = "https://yiliao.test03.qcw800.com/static/images/tab/user-header.png";
const tabList = reactive([
  { name: "我的内推官", activeLineWidth: "180" },
  { name: "已内推", activeLineWidth: "108" },
]);
const activeTab = ref(0);
const list: any = reactive([]);
//list = [...list, ...list];

const tabChange = (e) => {
    activeTab.value = e.index;
};
async function getTeacherRecommendList() {
  let params:any = {

  }
  let result = await userTeacherRecommend(params);
  console.log('我的内推官 res list:::', result);
  for (let i = 0; i < result.list.length; i++) {
    const r = result.list[i]
    let rr: any = {
      teacher_name: r.user.name,
      teacher_avatar: r.user.avatar,
      school_name: r.user.teacher.school.name,
      college_name: r.user.teacher.college.name,
      duty_name: r.user.teacher.duty.name,
    }
    rr.tabs = [
      {
        label: rr.school_name,
        ico: "icon-a-zu121328_1",
      },
      {
        label: rr.college_name,
        ico: "icon-a-zu121326_1",
      },
      {
        label: rr.duty_name,
        ico: "icon-a-zu121327_1",
      },
    ]
    list.push(rr)
  }
}

const jobList:any = reactive([])
async function getJobList() {
    let params : any = {
      status_recommend: 1
    }
    let result = await userJobList(params);
    console.log('以内推职位列表 res list:::', result);
    //vue3传递result的值到子组件JobList中的属性jobList中
    jobList.splice(0, jobList.length);
    for (let i = 0; i < result.list.length; i++) {
      const r = result.list[i]
      let rr = {
        job_name: r.name,
        job_id: r.id,
        salary_min: r.salary_min,
        salary_max: r.salary_max,
        salary_count: r.salary_count,
        province: r.province.name,
        city: r.city.name,
        job_nature: r.nature,
        qualifications: '',
        highlights: r.highlights,
        company_id: r.company.id,
        company_logo: r.company.url_logo,
        company_name: r.company.name,
        company_type: r.company.type == 1 ? '民营' : r.company.type == 2 ? '国企' : '合资',
        company_listed: r.company.listed == 1 ? '未上市' : '上市',
        like: r.like,
        like_img: r.like == 1 ? home06 : home10,
        hr_avatar: r.user.avatar,
        hr_name: r.user.name,
        hr_duty: r.user.hr.duty.name,
        hr_id: r.user.id,
      }
      let qualifications = ''
      for (let j = 0; j < r.qualifications.length; j++) {
        qualifications += r.qualifications[j] + ' '
      }
      rr.qualifications = qualifications
      jobList.push(rr)
    }
  }

onLoad(() => {
  getTeacherRecommendList()
  getJobList()
});
</script>
